package cn.rkylin.oms.common.utils;


/**
 * Sku工具类
 * 处理平台商品工具类
 *
 * @author liming
 */
public class SkuUtil {
    /**
     * 获取Ec规格名称
     * 将 1627207:28341:颜色分类:黑色;20509:28315:尺码:M 转成 颜色分类:黑色;尺码:M
     *
     * @param topSkuName
     * @return
     */
    public static String getEcSkuName(String topSkuName) {
        if (!topSkuName.contains(";")) {
            return topSkuName;
        } else {
            // 分别处理每一个，取后2个元素
            String keyValue = "";
            try {
                String[] skuProps = topSkuName.split(";");

                for (int length = 0; length < skuProps.length; length++) {
                    String[] skuProp = skuProps[length].split(":");
                    keyValue += skuProp[2] + ":" + skuProp[3] + ";";
                }

                keyValue = keyValue.substring(0, keyValue.length() - 1);
            }catch (Exception ex){
                keyValue=topSkuName;
            }
            return keyValue;
        }
    }
}
